////////////////////////////////////////////////////////////////////////////////
// Copyright 2006 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   PropertyIterator.java
// AUTHOR           :   ric.yik
// DATE CREATE      :   2006/5/12
// DESCRIPTION      :   
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2006/5/12      ric.yik         1.0                 source is created.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.common.util;

import java.util.Collection;
import java.util.Iterator;

import com.erp.framework.util.BeanUtil;
import com.erp.framework.util.CommonUtil;

public class PropertyIterator extends CompositeIterator {

    public PropertyIterator(Iterator component) {
        super(component);
    }

    public PropertyIterator(Collection collection) {
        super(CommonUtil.getIterator(collection));
    }

    private String property;

    public String getProperty() {
        return property;
    }

    public PropertyIterator setProperty(String property) {
        this.property = property;
        return this;
    }

    public Object next() {
        Object next = super.next();
        Object value = null;
        if (next != null) {
            if (CommonUtil.isEmpty(this.getProperty())) {
                throw new IllegalArgumentException("PropertyIterator.getProperty() should not be empty");
            }
            value = BeanUtil.getPropertyDefault(next, this.getProperty());
        }
        return value;
    }

}
